<template>
  <div>
      <h1>修改密码</h1>
      <div class="editPassword">
      <el-form label-width="auto" ref="passwordForm" :model="passwordForm">
          <el-form-item label="原密码">
            <el-input type="password" placeholder="输入原密码" v-model="passwordForm.oriPwd"></el-input>
          </el-form-item>
          <el-form-item label="新密码">
            <el-input type="password" placeholder="输入新密码" v-model="passwordForm.newPwd"></el-input>
          </el-form-item>
          <el-form-item label="确认密码">
            <el-input type="password" placeholder="再次输入新密码" v-model="passwordForm.newPwd2"></el-input>
          </el-form-item>
     </el-form>
     <span slot="footer" class="dialog-footer">
          <el-button type="danger" @click="editPassword()">确 定</el-button>
    </span>
    </div>
  </div>
</template>

<script>
export default {
    data(){
        return{
            passwordForm:{
                oriPwd:'',
                newPwd:'',
                newPwd2:''
            },
        }
    },
    created(){},
    methods:{
        //修改密码
    editPassword(){
      if(this.passwordForm.newPwd == this.passwordForm.newPwd2){
        this.axios.post(`/web/student/student/mine/updatePassword`,{
        oriPwd:this.passwordForm.oriPwd,
        newPwd:this.passwordForm.newPwd
      }).then(() => {
         this.$refs.passwordForm.resetFields();
         this.passwordForm.newPwd = '',
         this.passwordForm.oriPwd = '',
         this.passwordForm.newPwd2 = '',
         this.passwordDialog = false
         this.logout()
         this.$message.success('密码修改成功，请重新登录')
      })
      }else{
        this.$message.error('两次密码输入不一致')
      }  
    },
    //登出
    logout(){
      this.axios.post(`/base/logout`,{})
      .then((res) => {
       document.cookie = "stuToken=0;expires=" + new Date().toUTCString();
      //  window.location.href=`http://localhost:8080/`
       window.location.href = res
      })
    }
    }
}
</script>

<style scoped>
h1{
    margin: 60px 0 60px 586px;
}
.editPassword{
    margin: 0 auto;
    width: 684px;
}
.dialog-footer{
    margin-left: 69px;
}
</style>